"""
requests模块：
    python中原生的一款基于网咯请求的模块
    功能强大 简单便捷 效率极高
    作用：模拟浏览器发请求
    如何使用：
        — 指定URL
        — 发起请求
        — 获取响应数据
        — 持久化存储
    response.encoding = 'utf-8'  # 解决乱码问题

    结束后记得关闭程序 close
"""

import requests, json

# 爬取新浪
# url = 'https://www.sina.com.cn/'
# response = requests.get(url=url)
# response.encoding = 'utf-8'
# page_text = response.text
# with open('xinlang.html', 'w', encoding='utf-8') as f:
#     f.write(page_text)
# print('爬取结束')


# 带参数的url
# UA伪装 让爬虫对应的请求载体身份标识伪装成某一款浏览器
# url = 'https://www.sogou.com/web'
# # UA伪装 将对应的User-Agent封装到一个字典中
# header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0'}
# name = input('输入搜索内容：')
# dic = {'query': name}
# response = requests.get(url=url, params=dic, headers=header)
# response.encoding = 'utf-8'  # 解决乱码问题
# page_text = response.text
# with open(name + '.html', 'w', encoding='utf-8') as f:
#     f.write(page_text)
# print(name, '爬取完成')


# 爬取百度翻
# url = 'https://fanyi.baidu.com/sug'
# ua = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"}
# name = input('输入翻译内容：')
# dic = {'kw': name}
# response = requests.post(url=url, data=dic, headers=ua)
# dic_obj = response.json()
# filename = name + '.json'
# f = open(filename, 'w', encoding='utf-8')
# json.dump(dic_obj, fp=f, ensure_ascii=False, indent=6)
# f.close()
# print('翻译完毕')


# 豆瓣电影爬取
# url = 'https://movie.douban.com/j/chart/top_list'
# ua = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"}
# dic = {
#     'type': '5',
#     'interval_id': '100:90',
#     'action': '',
#     'start': '0',
#     'limit': '30',
# }
# response = requests.get(url=url, params=dic, headers=ua)
# list_data = response.json()
# f = open('doupan.json', 'w', encoding='utf-8')
# json.dump(list_data, fp=f, ensure_ascii=False, indent=8)
# print('结束')


# 肯德基
# url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx/?op=keyword'
# ua = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"}
# name = input('输入门店信息：')
# dic = {
#     'cname': '',
#     'pid': '',
#     'keyword': name,
#     'pageIndex': 1,
#     'pageSize': 10,
# }
# response = requests.post(url=url, data=dic, headers=ua)
# page_text = response.text
# page_json = json.loads(page_text)
# f = open(name+'.json', 'w', encoding='utf-8')
# json.dump(page_json, fp=f, ensure_ascii=False, indent=8)
# print('OK')













